package top.abrsm.mapper;

import org.apache.ibatis.annotations.Select;
import top.abrsm.entity.CommentEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * <p>
 * 商品评论表 Mapper 接口
 * </p>
 *
 * @author WuZH
 * @since 2023-11-18
 */
@Mapper
public interface CommentMapper extends BaseMapper<CommentEntity> {

    @Select (value = "<script>select * from comment_info ci left join student_info si on ci.stuId = si.id<where><if test='orderId!=null'>ci.orderId=#{orderId}</if><if test='stuId!=null'> and ci.stuId=#{stuId}</if><if test='productId!=null'> and ci.productId=#{productId}</if><if test='productScore!=null'> and ci.productScore=#{productScore}</if></where> order by ci.createTime desc limit #{limit}, #{offset}</script>")
    List<CommentEntity> queryList ( String orderId, String stuId, String productId, Integer productScore, Integer limit, Integer offset);

    @Select (value = "<script>select count(1) from comment_info ci left join student_info si on ci.stuId = si.id<where><if test='orderId!=null'>ci.orderId=#{orderId}</if><if test='stuId!=null'> and ci.stuId=#{stuId}</if><if test='productId!=null'> and ci.productId=#{productId}</if><if test='productScore!=null'> and ci.productScore=#{productScore}</if></where></script>")
    Integer queryCount (String orderId, String stuId, String productId, Integer productScore);

}
